
import { ref } from 'vue';
import { usePageTitle } from '@/store/base.js';
import { useRouter } from 'vue-router';

export default function() {
    const navBarIsShow = ref(true);
    const tabBarIsShow = ref(false);
    const initIndex = ref(0);  //  初始化显示

    const { setPageTitle } = usePageTitle();
    const router = useRouter();

    //  指定页面
    const tabBarList = [
    { path: '/Home', name: '首页', icon: 'icon-jiachangketang--huise' },
    { path: '/PointsMall', name: '积分商城', icon: 'icon-jifenshangcheng' },
    { path: '/PersonalCenter', name: '我的', icon: 'icon-gerenzhongxin' },
    ].map(item => {
    item.selectColor = 'rgb(64, 158, 255)';
    item.color = '#CCCCCC';
    return item;
    });

    //  根据上面的页面生成路由表
    const routerObj = tabBarList.reduce((prev, item, index) => {
      item.index = index;
      prev[item.path] = item;
      return prev;
    }, {})

    //  创建 排除路由表
    const excuteNavObj = {
      '/Home': true
    }

    //  全局监听 路由是否是指定的
    router.beforeEach((to, form) => {
      //  设置
    setPageTitle( to.name );
    const curRouter = routerObj[ to.path ];
    // console.log('curRouter:',curRouter);

    if( curRouter ) {
        //  记录位置
        initIndex.value = curRouter.index;
        // console.log('initIndex.value:',initIndex.value);
        // navBarIsShow.value = false;
        tabBarIsShow.value = true;
    } else {
        // navBarIsShow.value = true;
        tabBarIsShow.value = false;
    }

    if(excuteNavObj[ to.path ]) {
      navBarIsShow.value = false;
    } else {
      navBarIsShow.value = true;
    }
}) 

    return {
        navBarIsShow,
        tabBarIsShow,
        initIndex,
        tabBarList
    }
}